//package com.itheima.common.filter;
//
//import com.alibaba.fastjson.JSON;
//import com.itheima.common.Result;
//import com.itheima.common.utils.JwtUtils;
//import lombok.extern.slf4j.Slf4j;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
//
//@Slf4j
//@WebFilter(urlPatterns = "/*")
////定义一个类，实现一个标准的Filter过滤器的接口
//public class DemoFilter implements Filter {
//    @Override //初始化方法, 只调用一次
//    public void init(FilterConfig filterConfig) throws ServletException {
//        System.out.println("init 初始化方法执行了");
//    }
//
//    @Override //拦截到请求之后调用, 调用多次
//    public void doFilter(ServletRequest serverletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        System.out.println("Demo 拦截到了请求...放行前逻辑");
//        //放行
//        HttpServletRequest request = (HttpServletRequest)serverletRequest;
//        HttpServletResponse response = (HttpServletResponse)servletResponse;
//
//        String token = request.getHeader("Token");
//        String url = request.getRequestURL().toString();
//
//        if(url.contains("login")){
//            filterChain.doFilter(serverletRequest,servletResponse);
//            return;
//        }
//
//        try {
//            JwtUtils.parseJWT(token);
//            filterChain.doFilter(serverletRequest,servletResponse);
//        } catch (Exception e) {
//            Result<?> notLogin = Result.error("NOT_LOGIN");
//            String json = JSON.toJSONString(notLogin);
//            response.setContentType("application/json;charset = utf-8");
//
//            response.getWriter().write(json);
//
//        }
//
//
//    }
//
//    @Override //销毁方法, 只调用一次
//    public void destroy() {
//        System.out.println("destroy 销毁方法执行了");
//    }
//}